<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

	<script type="text/javascript">
		var a = document.documentElement.clientHeight - 110;
		var b = document.documentElement.clientWidth - 30;
		var dbRowIndex = -1; 
		var parentFlowId = -1;
		
		
		$(function(){
			a = document.documentElement.clientHeight - 110;
			b = document.documentElement.clientWidth - 30;
			var id= $('#execId').val();
			loadButns('XTPlan','PLANBUTTONS');
			execDategrid('XTPlan','XTPlan','PLANDATALIST',id);
			showInsertLink();
			loadButns('Link','LINKBUTTONS');
			loadDategrid('InsertLink','InsertLink','LINKDATALIST');
		});
		
		var divName="";
		//加载按钮  传入参数butnId
		function loadButns(butnId,divID){
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath}/framework/buttonsList',
				data:{'butnId':butnId},//XTPlan
				success:function(data){
					if(data == ""){
						alert("按钮数据为空");
					}else{
						//请求一个组织按钮的方法
						var buttons = data;
						var butHTML = "";
						for(var i = 0; i < buttons.length; i++){
							butHTML += formatButtons(buttons[i]);
						}
						$("#"+divID+"").html(butHTML);
						$.parser.parse();  //重新编译界面
					}
				}
			});
		}
		
		//加载datagrid  传入参数dsId(配置DS的数据源ID)；colId（//加载查询条件或当前界面的主表信息     传入参数colId）
		function loadDategrid(dsId,colId,divId){
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath}/framework/listQueryJson',
				data:{'dsId':dsId,'colId':colId,'execFlag':'','flag':''},
				success:function(data){
					if(data==""){
						alert("数据为空");
					}else{
						//给datagrid赋列值，还有rows
						mdatagrid(data,divId);
					}
				}
			});
		}
		
		function execDategrid(dsId,colId,divId,execId){
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath}/framework/listQueryJson',
				data:{'dsId':dsId,'colId':colId,'execFlag':'T','id':execId,'flag':''},
				success:function(data){
					if(data==""){
						alert("数据为空");
					}else{
						//给datagrid赋列值，还有rows
						mdatagridX(data,divId);
					}
				}
			});
		}
		//组合datagrid信息  不用改任何信息
		function mdatagrid(data,divId){ //传入的是queryJson 里面就有columns和rows
			var lastIndex;
			$("#"+divId+"").datagrid({
				iconCls:'icon-save',
				width:b,
				height:a+20,
				nowrap: false,
				striped: true,				 
				collapsible:true,
				autoRowHeight: false,		
				sortOrder: 'desc',
				remoteSort: false,
				fitColumns:true,
				frozenColumns:[[
	                {field:'ck',checkbox:true}
				]],
				columns:[[]],
				rownumbers:true,
				onDblClickRow:function(rowIndex,rowData){
					if(divId == 'PLANDATALIST'){
						//如果是现有的环节数据窗口，则绑定双击事件
						$.ajax({
							url:'${pageContext.request.contextPath}/node/flowNode',
							data:{managerId:rowData.MANAGE_ID},
							success:function(data){
								if(data.msg=='success'){
									$.messager.alert('提示框','打开窗口：编号['+data.info+"]",'info');
								}else{
									$.messager.alert('错误提示',data.msg,'error');
								}
							}
						});
					}
				}
			});
			
			var dataGrid = $("#"+divId+"");
			dataGrid.datagrid(jointColumn(data.columns));//根据配置选项，生成datagrid  
			//alert(data.rows.length);
			dataGrid.datagrid("loadData", data);
		}
		
		function mdatagridX(data,divId){ //传入的是queryJson 里面就有columns和rows
			var lastIndex;
			$("#"+divId+"").datagrid({
				iconCls:'icon-save',
				width:b-20,
				height:a,
				nowrap: false,
				striped: true,				 
				collapsible:true,
				sortOrder: 'desc',
				remoteSort: false,
				singleSelect:true,
				fitColumns:true,
				columns:[[]],
				rownumbers:true,
				onDblClickRow:function(rowIndex,rowData){
					if(divId == 'PLANDATALIST'){
						//如果是现有的环节数据窗口，则绑定双击事件
						$.ajax({
							url:'${pageContext.request.contextPath}/node/flowNode',
							data:{managerId:rowData.MANAGE_ID},
							success:function(data){
								if(data.msg=='success'){
									$.messager.alert('提示框','打开窗口：编号['+data.info+"]",'info');
								}else{
									$.messager.alert('错误提示',data.msg,'error');
								}
							}
						});
					}
				},onClickRow:function(rowIndex, rowData){
					dbRowIndex = rowIndex;
				}
			});
			var dataGrid = $("#"+divId+"");
			dataGrid.datagrid(jointColumn(data.columns));//根据配置选项，生成datagrid  
			//alert(data.rows.length);
			dataGrid.datagrid("loadData", data);
		}
		//点击插入环节按钮
		function insertPlan(){
			parentFlowId = 1;
			$('#InsertLink').dialog('open');
			$('#LINKDATALIST').datagrid('clearSelections');
			$('#LINKDATALIST').datagrid({singleSelect:false});
			
		}
		//点击插入父节点
		function insertParentPlan(){
			if(dbRowIndex == -1 ){$.messager.alert('提示框','请选择一行数据','info');return;}
			parentFlowId = 2;//插入父节点
			$('#InsertLink').dialog('open');
			$('#LINKDATALIST').datagrid('clearSelections');
			$('#LINKDATALIST').datagrid({singleSelect:true});
		}
		//删除父环节
		function deleteParentPlan(){
			 var selRow = $('#PLANDATALIST').datagrid('getSelected');
			if(selRow == null){$.message.alert('提示','请选择一条环节点记录');return;};
			 $.messager.confirm('提示','确定删除父环节?', function(btn2){
							    //点击确定则保存,否则取消
								    if (btn2) {
								    	selRow.PARENT_FLOW_ID = "";
										$('#PLANDATALIST').datagrid('refreshRow', dbRowIndex);
								    }
								});
		}
					
		function showInsertLink(){
			$('#InsertLink').dialog({
				fit:true,
				collapsible: true,
				minimizable: true,
				maximizable: true,
				title:'插入环节',
				maximized:true
			});
			$('#InsertLink').dialog('close');
		}
		function existWindows(){
			$('#InsertLink').dialog('close');
		}
	</script>
</head>
<body  onresize="resizeGrid();">
	<form action="" method="post" id="queryForm1">
		<table cellpadding="0" cellspacing="0" style="width: 100%">
			<tr>
				<td style="vertical-align: top; padding-bottom: 10px;padding-top: 15px;">
					<!-- 部分按钮 -->
					<div id="PLANBUTTONS" style="padding-left: 20px;"></div>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<!-- 现有环节 数据列表 -->	
					<table  id="PLANDATALIST"></table>
				</td>
			</tr>
		</table>
	</form>
	<!--点击 -->
	<div id="InsertLink">
		<table cellpadding="0" cellspacing="0" style="width: 100%">
			<tr>
				<td style="vertical-align: top;">
					<!-- 部分按钮 -->
					<div id="LINKBUTTONS" style="width:195px;padding-left: 20px;"></div>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<!-- 所有环节 数据列表 -->	
					<table  id="LINKDATALIST"></table>
				</td>
			</tr>
		</table>
	</div>
	<input type="hidden" id="configId1" value="${configId}"/>
	<input type="hidden" id="funcsId1" value="${funcsId}"/>
	<input type="hidden" id="execId" value="${id}"/>
</body>
</html>